package com.soul.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.soul.common.msg.ApiResult;
import com.soul.sys.bean.dto.dict.DictTypeAddDto;
import com.soul.sys.bean.dto.dict.DictTypeSearchDto;
import com.soul.sys.bean.dto.dict.DictTypeUpdateDto;
import com.soul.sys.bean.vo.DictTypeVo;
import com.soul.sys.service.DictService;
import com.soul.sys.service.DictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.soul.common.controller.BaseController;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author sws
 * @since 2023-09-27 10:08:12
 */
@RestController
@RequestMapping("/dictType")
@Api(value="dictType", tags = "字典接口")
public class DictTypeController extends BaseController {

    @Autowired
    private DictTypeService dictTypeService;

    /**
     * 查询数据字典,分页
     */
    @GetMapping("/{current}/{page}/list")
    @ApiOperation(value = "获取字典分页")
    public ApiResult<IPage<DictTypeVo>> queryList(@PathVariable("current") Integer current,
                                                  @PathVariable("page") Integer page,
                                                  DictTypeSearchDto searchDto){
        IPage<DictTypeVo> dictTypeVoIPage = this.dictTypeService.queryDictTypeList(current, page, searchDto);
        return ApiResult.success(dictTypeVoIPage);
    }

    @GetMapping("/{id}/info")
    @ApiOperation(value = "获取字典详细信息")
    public ApiResult<DictTypeVo> getDictType(@PathVariable Long id){
        DictTypeVo dictTypeInfo = this.dictTypeService.getDictTypeInfo(id);
        return ApiResult.success(dictTypeInfo);
    }
    /**
     * 新增字典
     * @param addDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增字典")
    public ApiResult<?> add(@RequestBody DictTypeAddDto addDto){
        this.dictTypeService.addDictType(addDto);
        return ApiResult.success();
    }

    /**
     * 修改字典
     * @param updateDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改字典")
    public ApiResult<?> add(@RequestBody DictTypeUpdateDto updateDto){
        this.dictTypeService.updateDictType(updateDto);
        return ApiResult.success();
    }

    /**
     * 删除字典
     * @param id
     * @return
     */
    @DeleteMapping("/{id}/del")
    @ApiOperation(value = "删除字典，根据id")
    public ApiResult<?> delete(@PathVariable("id") Long id){
        this.dictTypeService.deleteDictType(id);
        return ApiResult.success();
    }

}
